import os

def traverse_directory(directory, current_depth=0):
    print(f"当前处理目录: {directory}，当前深度: {current_depth}")
    for entry in os.scandir(directory):
        if entry.is_dir():
            current_depth += 1
            subdir_path = entry.path
            # print(entry.name)
            print(f"发现子目录: {subdir_path}，深度增加到 {current_depth}")
            # 递归调用处理子目录
            traverse_directory(subdir_path, current_depth)
            # 回溯时减少深度
            current_depth -= 1
        else:
            print(f"发现文件: {entry.path}")

# 调用函数，从 main_folder 开始遍历
traverse_directory("main_folder")